package com.example.leetcode.stack_deque;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;

/**
 * 滑动窗口的最大值
 */
public class MaxInWindows {
    public static void main(String[] args) {
        int[] num = new int[]{2,3,4,2,6,2,5,1};

        ArrayList<Integer> integers = maxInWindows(num, 3);
        System.out.println(integers);
    }

    public static ArrayList<Integer> maxInWindows (int[] num, int size) {
        ArrayList<Integer> res = new ArrayList<>();

        int max = Integer.MIN_VALUE;
        Deque<Integer> deque = new ArrayDeque<>();
        for (int i : num) {
            if (i > max) {
                max = i;
            }
            deque.add(i);
            if (deque.size() == 3) {
                res.add(max);
                deque.pop();
            }
        }

        return res;
    }
}
